import { MapHelper } from './MapHelper'

const helpers = new Map()

export const setHelper = (id, mapInstance) => {
  if (!helpers.has(id)) {
    const helper = new MapHelper(id, mapInstance)
    helpers.set(id, helper)
  }
  return helpers.get(id)
}

export const getHelper = (id) => {
  return new Promise((resolve) => {
    const timer = setTimeout(() => {
      resolve(helpers.get(id))
      clearTimeout(timer)
    }, 100)
  })
}

export const deleteHelper = (id) => {
  if (helpers.has(id)) {
    helpers.get(id)?.destroy()
    helpers.delete(id)
    return true
  } else {
    return false
  }
}
